package com.yunchen.BooksManagementSystem.manage.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import com.alibaba.fastjson.JSON;
import com.yunchen.BooksManagementSystem.manage.dao.adminDaoImpl;
import com.yunchen.BooksManagementSystem.user.entity.UserInformation;

@WebServlet(name = "FindAllStudentServlet", value = "/FindAllStudentServlet")
public class FindAllStudentServlet extends HttpServlet {
    private adminDaoImpl ad=new adminDaoImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<UserInformation> informations =null;
        try {
            informations=ad.findAllStudent();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        String jsonString= JSON.toJSONString(informations);
        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
